package pl.sar.auth.server.ejb.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table( name = "ROLES" )
public class Role implements Serializable
{

    private static final long serialVersionUID = -1348163243937956940L;

    @Id
    @GeneratedValue( strategy = GenerationType.IDENTITY )
    private long id;

    @Column( name = "name", unique = true, nullable = false )
    private String name;

    @Column( name = "valid" )
    private boolean valid;

    @Column( name = "description" )
    private String description;

    @OneToMany( cascade = CascadeType.ALL, mappedBy = "role" )
    private Collection< Permission > permissions;

    @ManyToMany( mappedBy = "roles" )
    private Set< User > users;

    public Role()
    {
    }

    public long getId()
    {
        return id;
    }

    public String getName()
    {
        return name;
    }

    public void setName( String name )
    {
        this.name = name;
    }

    public boolean isValid()
    {
        return valid;
    }

    public void setValid( boolean valid )
    {
        this.valid = valid;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription( String description )
    {
        this.description = description;
    }

    public Collection< Permission > getPermissions()
    {
        return permissions;
    }

    public void setPermissions( Collection< Permission > permissions )
    {
        this.permissions = permissions;
    }

    public Set< User > getUsers()
    {
        return users;
    }

    public void setUsers( Set< User > users )
    {
        this.users = users;
    }

}
